/**
 * Copyright (C) 2013 DaiKit.com - daikit4gxt-sample module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/commons
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.daikit4gxtsample.client.ui.field;

import java.util.ArrayList;
import java.util.List;

import com.daikit.daikit4gxt.client.action.DkBaseAsyncCallback;
import com.daikit.daikit4gxt.client.action.DkPagingRpcCallerWithInput;
import com.daikit.daikit4gxt.client.ui.fields.DkDynamicAsyncPagingCombobox;
import com.daikit.daikit4gxt.client.ui.forms.DkReferenceEditorGrid;
import com.daikit.daikit4gxtsample.client.Main;
import com.daikit.daikit4gxtsample.client.propertyaccess.CountryDetailPropertyAccess;
import com.daikit.daikit4gxtsample.shared.bean.CountryDetailData;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadResult;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;


/**
 * Country Detail Reference Editor
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 */
public abstract class CountryDetailReferenceEditorGrid extends DkReferenceEditorGrid<CountryDetailData>
{

	/**
	 * Country Detail Reference editor constructor
	 * 
	 * @param store
	 *           the {@link ListStore}
	 */
	public CountryDetailReferenceEditorGrid(final ListStore<CountryDetailData> store)
	{
		super(store, getColumnConfigs(), CountryDetailPropertyAccess.INSTANCE);
	}

	private static final List<ColumnConfig<CountryDetailData, ?>> getColumnConfigs()
	{
		final List<ColumnConfig<CountryDetailData, ?>> columnConfigs = new ArrayList<ColumnConfig<CountryDetailData, ?>>();

		final ColumnConfig<CountryDetailData, String> columnName = new ColumnConfig<CountryDetailData, String>(
				CountryDetailPropertyAccess.INSTANCE.name(), 120, Main.gwtSampleI18n().country_detail_name());
		final ColumnConfig<CountryDetailData, String> columnCountryName = new ColumnConfig<CountryDetailData, String>(
				CountryDetailPropertyAccess.INSTANCE.countryName(), 120, Main.gwtSampleI18n().country_detail_country_name());
		final ColumnConfig<CountryDetailData, Integer> columnSalesForecast = new ColumnConfig<CountryDetailData, Integer>(
				CountryDetailPropertyAccess.INSTANCE.salesForecast(), 120, Main.gwtSampleI18n().country_detail_sale_forecast());

		columnConfigs.add(columnName);
		columnConfigs.add(columnCountryName);
		columnConfigs.add(columnSalesForecast);

		return columnConfigs;
	}

	@Override
	protected ComboBox<CountryDetailData> createSelectionCombobox()
	{
		return new DkDynamicAsyncPagingCombobox<CountryDetailData>(CountryDetailPropertyAccess.INSTANCE.key(),
				new DkPagingRpcCallerWithInput<CountryDetailData>()
				{
					@Override
					public void callLoadRpc(final String inputText, final PagingLoadConfig pagingLoadConfig,
							final DkBaseAsyncCallback<PagingLoadResult<CountryDetailData>> callback)
					{
						Main.controller().rpcProduct().getCountryDetails(inputText, pagingLoadConfig, callback);
					}
				});
	}

	@Override
	public String getDeleteTooltip()
	{
		return "Delete this Country Detail";
	}
}
